
#include "stdafx.h"
#include "tmediasource.h"

TMediaSource::TMediaSource( QString filePath)
{
	if(!filePath.isEmpty())
	{
		m_file.setFileName(filePath);
		m_file.open(QFile::ReadOnly);
	}
    m_nCurOffset = 0;
}

TMediaSource::~TMediaSource()
{
		if(m_file.isOpen())
			m_file.close();
}

void TMediaSource:: setFilePath(QString filePath)
{
	if(m_file.isOpen())
		m_file.close();
	 m_file.setFileName(filePath);
	 m_file.open(QFile::ReadOnly);
	 m_nCurOffset = 0;
}

int TMediaSource::read(unsigned char *buf, int dwBytesToRead)
{
	if(!m_file.isOpen())
		return 0;
	m_file.seek(m_nCurOffset);
	int byteRead = m_file.read((char*)buf, dwBytesToRead);
	return byteRead;
}

bool TMediaSource::seek(long long pos)
{
	m_nCurOffset = pos;
	return true;
}

long long TMediaSource::size()
{
	return m_file.size();
}
